//
// Created by user on 2022/3/9.
//
#include <vector>
#include <unordered_map>
using namespace std;
vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {
    unordered_map<int, int> map;
    for (int n1:nums1) {
        map[n1]++;
    }
    vector<int>res;
    for (int n2:nums2) {
        if(map.count(n2) && map[n2]>0){
            res.push_back(n2);
            map[n2]--;
        }
    }
    return res;
}